﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using CustomsSystem.BLL;
using CustomsSystem.Model;


namespace WEB.feetype
{
    public partial class index_fee : System.Web.UI.Page
    {
        DataSet ds = new DataSet();
        FeeTypeManage FM = new FeeTypeManage();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ds = FM.GetAllList();
                GridView1.DataSource = ds;
                GridView1.DataBind();
            }
        }

      

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("Addfee.aspx");
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string EMPNO = Convert.ToString(GridView1.DataKeys[e.RowIndex].Value);
           //不允许删除已填入费用
            CustomsSystem.BLL.BillManage ftm =new BillManage ();
            if (ftm.Exists(EMPNO))
            { Response.Write("<Script>alert('该费用类型已经使用，无法删除!')</script>"); }
            else
            {
                if (FM.Delete(EMPNO))
                {
                    Response.Write("<Script>alert('删除成功!')</script>");

                    ds = FM.GetFeeList("");
                    GridView1.DataSource = ds;
                    GridView1.DataBind();
                }
                else
                    Response.Write("<Script>alert('删除失败!')</script>");
            }
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            GridView1.SelectedIndex = e.NewEditIndex;
            string feeno = GridView1.SelectedRow.Cells[0].Text;
            Session["feetypeno"] = feeno;
            Response.Redirect("Chancefee.aspx?feetypeno=" + feeno);
        }

        /// <summary>
        /// 弹窗确认
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //如果是绑定数据行         
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除：\"" + e.Row.Cells[1].Text + "\"该费用类别吗?')");
                }
            }
        }

        /// <summary>
        /// 允许分页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
    }
}